package test.java.com.playjoy;

import com.playjoy.Application;
import com.playjoy.dao.UserRepository;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.SpringApplicationConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;


/**
 * Created by asus on 2016/11/11.
 */
@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(Application.class)
public class ApplicationTest1 {

    @Autowired
    private UserRepository userRepository;

    @Test
    public void test() throws Exception {
        // 创建10条记录
		/*userRepository.save(new User("AAA", 10));
		userRepository.save(new User("BBB", 20));
		userRepository.save(new User("CCC", 30));
		userRepository.save(new User("DDD", 40));
		userRepository.save(new User("EEE", 50));
 		userRepository.save(new User("GGG", 70));
		userRepository.save(new User("HHH", 80));
		userRepository.save(new User("III", 90));
		userRepository.save(new User("JJJ", 100));*/

        // 测试findAll, 查询所有记录
        Assert.assertEquals(9, userRepository.findAll().size());

        // 测试findUser, 查询姓名为FFF的User
        Assert.assertEquals(10, userRepository.findByName("AAA").getAge());



		/*// 测试删除姓名为AAA的User
		userRepository.delete(userRepository.findByName("AAA"));
		   // 测试findByName, 查询姓名为FFF的User
        Assert.assertEquals(50, userRepository.findByName("EEE").getAge().longValue());
         // 测试findByNameAndAge, 查询姓名为FFF并且年龄为60的User
        Assert.assertEquals("AAA", userRepository.findByNameAndAge("AAA", 10).getName());

		// 测试findAll, 查询所有记录, 验证上面的删除是否成功
		Assert.assertEquals(9, userRepository.findAll().size());*/

    }


}
